package com.heisenhub.api.logsapi.async;

import com.heisenhub.api.logsapi.service.LogsRecordsService;
import com.heisenhub.logs.common.qo.GMQo;
import com.heisnenhub.common.module.utils.Api;
import com.heisnenhub.common.module.utils.GsonUtils;
import com.heisnenhub.common.module.utils.SpringUtils;
import lombok.extern.slf4j.Slf4j;

import java.util.TimerTask;

@Slf4j
public class LogsAsyncFactory {

    private static LogsRecordsService operateService = SpringUtils.getBean(LogsRecordsService.class);


    /**
     * 保存操作日志
     */
    protected static TimerTask saveLog(GMQo gmQo){
        return new TimerTask() {
            @Override
            public void run() {
                Api api = operateService.save(gmQo.buildOperateLog());
                if(api == null || !api.isOk()){
                    log.info("【保存操作日志失败】 对象："+ GsonUtils.toJson(gmQo));
                }
            }
        };
    }

}
